<template>
  <div class="dashboard-container">
    <div class="app-container">
      <UploadExcel :on-success="onSuccess"></UploadExcel>
    </div>
  </div>
</template>

<script>
import { importEmployee } from '../employees/employees'
export default {
  name: '',
  components: {},
  data() {
    return {

    }
  },
  created() {},
  mounted() {},
  methods: {
    async onSuccess({ header, results }) {
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      const data = results.map(t => {
        const item = {}
        for (const key in t) {
        // 中转英文
          const newKey = userRelations[key]
          // 修改key，新建一个对象
          item[newKey] = t[key]
        }
        return item
      })
      // 发请求
      await importEmployee(data)
      // 提示成功
      this.$message.success('操作成功')
    }
  }
}
</script>

  <style lang="scss" scoped>

  </style>
